#!/usr/bin/python
# send_String.py : Sends a sentence to the TRIPS page and gets its semantics analysis and parse.
# Author: Federico Cirett Galan
PGK = "ua_cs665_trips"

import sys
import string
import getopt
# ROS 
import roslib; roslib.load_manifest('ua_cs665_trips')
import rospy
from std_msgs.msg import String
from ua_cs665_trips.srv import *
#
def main(argv):
    try:
       opts, args = getopt.getopt(argv,"s:h",["sentence=","help"])
    except getopt.GetoptError,err:
       print str(err)
       usage()
       sys.exit(2)
    for opt, arg in opts:
       if opt in  ("-s", "--sentence"):
          resp = send_sentence(arg)
          if resp.response == True:
             print "The sentence was processed succesfully"
          else:
             print "Something is wrong with the service"
       elif opt in ("-h", "--help"):
          usage()
          sys.exit(2)
    if len(opts) == 1:
       usage()
       
def send_sentence(sentence):
    rospy.wait_for_service('process_string_server')
    try:
        analyze_sentence = rospy.ServiceProxy('process_string_server', TripsProcess)
        analyze_sentence(sentence)       
    except rospy.ServiceException, e:
        print "Service call failed: %s"%e

def usage():
    print "send_string.py -s:'a sentence example' -h"
    print "send_string.py --sentence='a sentence example' --help"

if __name__ == "__main__":
    main(sys.argv[1:])
